package com.leo.blog.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * @Classname DateUtils
 * @Description TODO
 * @Date 2022/11/23 21:09
 * @Created by XiongXiong
 * @Author: X.I.O
 */
public class DateUtils {

    public static String getTimeStr(){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return sdf.format(new Date());
    }

    public static Date getExpireDate(int secords){
        Calendar cal = Calendar.getInstance();
        cal.add(Calendar.SECOND,secords);
        return cal.getTime();
    }

    public static Date getDateByFormat(String str,String formart){
        if(str==null || "".equals(str)){
            return null;
        }
        try {
            SimpleDateFormat sdf = new SimpleDateFormat(formart);
            return sdf.parse(str);
        }catch (ParseException e){
            e.printStackTrace();
        }
        return null;
    }
}
